/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package applet.source.action;

import applet.visualisation.VisuApp;
import java.awt.event.MouseEvent;
import java.util.Iterator;
import prefuse.controls.ControlAdapter;
import prefuse.data.Edge;
import prefuse.visual.EdgeItem;
import prefuse.visual.NodeItem;
import prefuse.visual.VisualItem;

/**
 *
 * @author krishen
 */
public class ShowNodeInfo extends ControlAdapter{

   private int size_table_edge =62;
   private String [] nodeInfos =  {"name", "status", "switch", "AS", "Type"};
   private String [] EdgesInfos =  {"status", "bandwidth", "delay", "Type", "Queue", "weight","length", "SOURCE_AS", "DESTINATION_AS", "linkType"};

    public ShowNodeInfo() {
        //this(null);
    }


    public void itemEntered(VisualItem item, MouseEvent e) {

        //


        if ( item instanceof NodeItem ){
            afficheInfoNode((NodeItem)item);
            afficheInfoEdge((NodeItem)item);
        }
    }

    private void afficheInfoNode (NodeItem item){

       for(int i=0; i< nodeInfos.length; i++){
           putInTableTabNode(item, nodeInfos[i], i);
       }
       //System.out.println("name =" +item.get("name"));

    }

    private void putInTableTabNode(NodeItem item, String value, int pos){
        try{           
            VisuApp.jTable2.getModel().setValueAt(item.get(value), pos, 1);


        }catch(Exception ex){
            System.out.println(ex.getStackTrace());
        }
    }


    
    private void afficheInfoEdge (NodeItem item){

        clearTable(size_table_edge);
        
        Iterator iter = item.edges();
        int pos = 0;
        while ( iter.hasNext() ) {
               EdgeItem eitem = (EdgeItem)iter.next();

               //eitem.setEndStrokeColor(200);


               VisuApp.jTable3.getModel().setValueAt("Link *", pos, 0);
               pos++;
               for(int i=0; i< EdgesInfos.length; i++){
                   try{
                       VisuApp.jTable3.getModel().setValueAt(eitem.get(EdgesInfos[i]), pos, 1);
                       VisuApp.jTable3.getModel().setValueAt(EdgesInfos[i], pos, 0);
                       pos++;
                   }catch(Exception ex){
                        // on ne fait rien
                   }
                   //putInTableTabEdge(eitem, EdgesInfos[i], pos);
               }
        }
            
       
       //System.out.println("name =" +item.get("name"));

    }
    
    private void clearTable(int size){
        
        for (int i =0; i< size ;i++){
            try{
                       VisuApp.jTable3.getModel().setValueAt("", i, 1);
                       VisuApp.jTable3.getModel().setValueAt("", i, 0);
                    
                }catch(Exception ex){
                        // on ne fait rien
                }
         
        }
        
    }




}
